<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Loader
 * @subpackage Autoloader
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 * @version    $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Autoloader interface
 *
 * @package    Zend_Loader
 * @subpackage Autoloader
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class ZFEngine_Loader_Autoloader implements Zend_Loader_Autoloader_Interface
{

    /**
     *
     * @param string $class
     * @return string|false Class name on success; false on failure
     */
    public function autoload($class)
    {
        
        $parts = explode('_', $class);

        $path = array_shift($parts) . DIRECTORY_SEPARATOR
            . array_shift($parts) . DIRECTORY_SEPARATOR
            . array_shift($parts) . DIRECTORY_SEPARATOR ;

        $resource = array_shift($parts);
        switch ($resource) {
            case 'Controller':
                $path .= 'controllers';
                break;
            case 'Model':
                $path .= 'models';
                break;
            case 'Form':
                $path .= 'forms';
                break;
            case 'View':
                $path .= 'views';
                switch (array_shift($parts)) {
                    case 'Helper':
                        $path .= 'helpers';
                        break;
                    case 'Filter':
                        $path .= 'filters';
                        break;
                }
                break;
            case 'Bootstrap':
                $path .= 'Bootstrap';
                break;
            default:
                $path .= $resource;
                break;
        }

        $path .= DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts) . '.php';
        
        if (Zend_Loader::isReadable($path)) {
            Zend_Loader::loadFile($path);
            return $class;
        // Хак для Доктриновских моделей переводов
        } elseif(strpos($class, 'Translation')) {
            return $class;
        } else {
            return false;
        }
    }
}
